using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FieldbookWin.FieldbookServices;

namespace FieldbookWin
{
    public partial class LoginForm : ChildForm
    {
        private bool colapsed = true;

        public LoginForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (colapsed)
            {
                this.Height += 50;
                this.groupBox2.Height += 50;
            }
            else
            {
                this.Height -= 50;
                this.groupBox2.Height -= 50;
            }
            colapsed = !colapsed;
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            ((MainForm)this.MdiParent).RegisterUserForm.Show();
        }

        private void btnSingIn_Click(object sender, EventArgs e)
        {
            MainForm mainForm = (MainForm)this.MdiParent;
            FieldbookServices.AutenhicationHeader aHeader = new FieldbookWin.FieldbookServices.AutenhicationHeader();
            aHeader.userName = this.txtUserName.Text;
            aHeader.passWord = this.txtPassword.Text;
            mainForm.FbService.AutenhicationHeaderValue = aHeader;
            Appuser user = mainForm.FbService.GetLoggedUser();
            if (user != null)
            {
                MessageBox.Show("Sucessful");
                mainForm.LoggedUser = user;
                mainForm.Text = String.Format("Filedbook! Logged in as {0} {1}", user.Firstname, user.Lastname);
                this.Hide();
            }
            else
            {
                MessageBox.Show("Error logging in");
            }
        }
    }
}